/*
 * FileName：WebsiteNewsCenterServiceImpl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.wx.wxcms.service.impl;

import com.smart.common.util.AjaxResult;
import com.smart.common.util.StringUtil;
import com.smart.common.util.Util;
import com.smart.wx.wxcms.dao.WebsiteNewsCenterMapper;
import com.smart.wx.wxcms.entity.WebsiteNewsCenter;
import com.smart.wx.wxcms.service.WebsiteNewsCenterService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;


/**
 * 网站模板-----新闻中心
 *
 * @author hermit
 * @version 2.0
 * @date 2018-07-12 23:13:45
 */
@Service
public class WebsiteNewsCenterServiceImpl implements WebsiteNewsCenterService {

    @Resource
    private WebsiteNewsCenterMapper websiteNewsCenterDao;

    @Override
    public WebsiteNewsCenter queryObject(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        return websiteNewsCenterDao.queryObject(websiteNewsCenter);
    }

    @Override
    public List<WebsiteNewsCenter> queryList(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        return websiteNewsCenterDao.queryList(websiteNewsCenter);
    }

    @Override
    public List<WebsiteNewsCenter> queryListByPage(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        return websiteNewsCenterDao.queryListByPage(websiteNewsCenter);
    }

    @Override
    public Integer queryCount(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        Integer ct = websiteNewsCenterDao.queryCount(websiteNewsCenter);
        return ct == null ? 0 : ct;
    }

    @Override
    public Integer insert(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        return websiteNewsCenterDao.insert(websiteNewsCenter);
    }

    @Override
    public Integer update(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        return websiteNewsCenterDao.update(websiteNewsCenter);
    }

    @Override
    public Integer delete(WebsiteNewsCenter websiteNewsCenter) throws Exception {
        String centerId = websiteNewsCenter.getId();
        if (StringUtil.isNotBlank(centerId)) {
            this.websiteNewsCenterDao.deleteBatch(Arrays.asList(centerId.split(",")));
        }

        return 1;
    }

    @Override
    public Integer deleteBatch(List<String> ids) throws Exception {
        return websiteNewsCenterDao.deleteBatch(ids);
    }

    @Override
    public AjaxResult saveOrUpdate(WebsiteNewsCenter center) throws Exception {

        String centerId = center.getId();
        if (StringUtil.isNotBlank(centerId)) { // 修改
            center.setUpdateTime(new Date());
            this.websiteNewsCenterDao.update(center);
        } else { // 新增
            center.setId(Util.getUUID());
            center.setCreateTime(new Date());
            center.setUpdateTime(new Date());
            this.websiteNewsCenterDao.insert(center);
        }

        return AjaxResult.saveSuccess();
    }
}
